package com.weibo.util;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
//hibernate 的辅助类
public final class HibernateUtil {
 private static SessionFactory sessionFactory=null;

	private HibernateUtil() {
	}

	static {
		try {
			Configuration cfg = new Configuration();
			cfg.configure();
			sessionFactory = cfg.buildSessionFactory();
		} catch (HibernateException ex) {
			throw new RuntimeException(
					"创建SessionFactory失败: " + ex.getMessage(), ex);
		}

	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public static Session getSession() {
		return sessionFactory.openSession();
	}
	
	
}




